package org.jeecgframework.web.system.util;

import org.apache.commons.codec.binary.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AesUtil {
    private static String PSEY = "1234123412ABCDEF";

    private static String PIV = "ABCDEF1234123412";


    public AesUtil(){

    }

    public static String Decrypt(String sSrc){
        try{
            SecretKeySpec skeySpec = new SecretKeySpec(PSEY.getBytes("UTF-8"), "AES");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            IvParameterSpec ivspe = new IvParameterSpec(PIV.getBytes("UTF-8"));
            cipher.init(2,skeySpec, ivspe);
            byte[] encrypted1 = Base64.decodeBase64(sSrc.getBytes("UTF-8"));
            byte[] original = cipher.doFinal(encrypted1);
            String originalString = new String(original, "utf-8");
            return originalString;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }

    public static void main(String[] args) {
        String password = "kQIioDTglszY/BSeXwO5CQ==";
        String encrypt = AesUtil.Decrypt(password);
        System.out.println(encrypt);
    }
}
